home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -serious- / hardware / psx-memcard_tool / src / psx.asc < prev   
Text File  |  1999-06-14  |  18KB  |  804 lines

  1. ' This is AMOS source code in ascii-format
  2.  
  3.  
  4. Parallel Open 
  5.  
  6. ' Just blank buffer screen for icons 
  7. Unpack 4 To 1
  8. Screen Hide 1
  9. ' Main screen
  10. Unpack 5 To 0
  11. ' Save names 
  12. Dim NAMES$(15)
  13.  
  14. ' Little stupid speed test 
  15. TIME=0
  16. Timer=0
  17. Repeat 
  18.    Inc TIME
  19. Until Timer>50
  20. SPEED=TIME/80000
  21. If SPEED>30 Then SPEED=30
  22.  
  23. ' Draw speed meter 
  24. Ink 6,6,6
  25. YPOSSE=47+SPEED*2
  26. Polygon 273,YPOSSE-2 To 273,YPOSSE+2 To 278,YPOSSE
  27.  
  28. TIME=0
  29. IMAGE=1
  30. Do 
  31.    ' Every tenth cycle = icon anim update 
  32.    Add UPDAT,1,0 To 9
  33.    
  34.    ' Set active screen
  35.    Screen 0
  36.    
  37.    ' Read keyboard if esc is pressed and free resources 
  38.    KB$=Inkey$
  39.    SC=Scancode
  40.    If SC=69
  41.       Parallel Close 
  42.       For ER=1 To 3
  43.          Erase ER
  44.       Next ER
  45.       End 
  46.    End If 
  47.    KB$=""
  48.    
  49.    ' Get mouse coordinates
  50.    COORDX=X Mouse-128
  51.    COORDY=Y Mouse-46
  52.    
  53.    ' TIME = little delay if gadgets are pressed 
  54.    If TIME>0
  55.       Dec TIME
  56.    End If 
  57.    
  58.    ' Zoom if right mouse button is pressed
  59.    If Mouse Key=2
  60.       Zoom 0,48,169,66,187 To 0,72,153,108,189
  61.    End If 
  62.    
  63.    ' Read left mouse button 
  64.    If(Mouse Key=1 and TIME=0)
  65.       
  66.       ' Speed adjustment part
  67.       If(COORDX>272 and COORDX<314)
  68.          If(COORDY>31 and COORDY<45)
  69.             Dec SPEED
  70.             If SPEED<0
  71.                SPEED=0
  72.             End If 
  73.          End If 
  74.          If(COORDY>109 and COORDY<123)
  75.             Inc SPEED
  76.             If SPEED>30
  77.                SPEED=30
  78.             End If 
  79.          End If 
  80.          ' Clear old speed triangle 
  81.          Ink 0,0,0
  82.          Bar 271,43 To 280,110
  83.          ' Draw new speed triangle
  84.          Ink 6,6,6
  85.          YPOSSE=47+SPEED*2
  86.          Polygon 273,YPOSSE-2 To 273,YPOSSE+2 To 278,YPOSSE
  87.          Wait 5
  88.       End If 
  89.       
  90.       
  91.       If(COORDX>22 and COORDX<100)
  92.          
  93.          ' Download 
  94.          If(COORDY>21 and COORDY<33)
  95.             ' Change gadget color
  96.             Ink 3
  97.             Paint 23,20
  98.             Ink 1
  99.             Paint 24,22
  100.             ' Card read sub part 
  101.             Gosub CARD_READ
  102.             ' Update icons 
  103.             Gosub MAKEICONS
  104.             ' Set delay
  105.             TIME=10
  106.             ' Restore gadget 
  107.             Ink 7
  108.             Paint 23,20
  109.             Ink 5
  110.             Paint 24,22
  111.          End If 
  112.          
  113.          ' Upload 
  114.          If(COORDY>41 and COORDY<53)
  115.             Ink 3
  116.             Paint 23,40
  117.             Ink 1
  118.             Paint 24,42
  119.             ' Card write sub part
  120.             Gosub CARD_WRITE
  121.             TIME=10
  122.             Ink 7
  123.             Paint 23,40
  124.             Ink 5
  125.             Paint 24,42
  126.          End If 
  127.          
  128.          ' Undelete 
  129.          If(COORDY>61 and COORDY<73 and Length(3)>0)
  130.             Ink 3
  131.             Paint 23,60
  132.             Ink 1
  133.             Paint 24,62
  134.             ' Mark saves in use
  135.             Gosub UNDEL
  136.             ' Update icons 
  137.             Gosub MAKEICONS
  138.             TIME=10
  139.             Ink 7
  140.             Paint 23,60
  141.             Ink 5
  142.             Paint 24,62
  143.          End If 
  144.          
  145.          ' Format 
  146.          If(COORDY>81 and COORDY<93)
  147.             Ink 3
  148.             Paint 23,80
  149.             Ink 1
  150.             Paint 24,82
  151.             ' Fill whole memorycard with zeros 
  152.             Gosub FOHMAT
  153.             TIME=10
  154.             Ink 7
  155.             Paint 23,80
  156.             Ink 5
  157.             Paint 24,82
  158.          End If 
  159.          
  160.          ' Load 
  161.          If(COORDY>111 and COORDY<123)
  162.             Ink 3
  163.             Paint 23,110
  164.             Ink 1
  165.             Paint 24,112
  166.             ' Load sub part
  167.             Gosub FILE_LOAD
  168.             ' If file was loaded 
  169.             If Length(3)>0
  170.                Gosub MAKEICONS
  171.             End If 
  172.             
  173.             TIME=10
  174.             Ink 7
  175.             Paint 23,110
  176.             Ink 5
  177.             Paint 24,112
  178.          End If 
  179.          
  180.          ' Save 
  181.          If(COORDY>131 and COORDY<143)
  182.             Ink 3
  183.             Paint 23,130
  184.             Ink 1
  185.             Paint 24,132
  186.             ' If there is data in memory 
  187.             If Length(3)>0
  188.                Gosub FILE_SAVE
  189.             End If 
  190.             
  191.             TIME=10
  192.             Ink 7
  193.             Paint 23,130
  194.             Ink 5
  195.             Paint 24,132
  196.          End If 
  197.          
  198.          ' Change icon
  199.          If(COORDX<37 and COORDY>161 and COORDY<173)
  200.             Ink 3
  201.             Paint 23,160
  202.             Ink 1
  203.             Paint 24,162
  204.             If IMAGE>1
  205.                Dec IMAGE
  206.                Gosub ICON
  207.             End If 
  208.             TIME=4
  209.             Ink 7
  210.             Paint 23,160
  211.             Ink 5
  212.             Paint 24,162
  213.          End If 
  214.          If(COORDX<37 and COORDY>181 and COORDY<193)
  215.             Ink 3
  216.             Paint 23,180
  217.             Ink 1
  218.             Paint 24,182
  219.             If IMAGE<15
  220.                Inc IMAGE
  221.                Gosub ICON
  222.             End If 
  223.             TIME=4
  224.             Ink 7
  225.             Paint 23,180
  226.             Ink 5
  227.             Paint 24,182
  228.          End If 
  229.          
  230.       End If 
  231.    End If 
  232.    
  233.    '  
  234.    If FRAMES>0 and UPDAT=9
  235.       Add FRAME,1,1 To FRAMES
  236.       Paste Bob 49,170,FRAME
  237.    End If 
  238.    Wait Vbl 
  239.    
  240. Loop 
  241. Data "$VER: PSX-MEMCARD TOOL v0.07"
  242.  
  243.  
  244. '----------------------------------------------------------
  245. ' Change colors 16 to 31, get icons
  246. ' IMAGE = current save 
  247. ICON:
  248. Screen 0
  249.  
  250. ' Check if current save block is in use & top block  
  251. If Peek(Start(3)+IMAGE*$80)=$51
  252.    
  253.    ' Icon window to black 
  254.    Ink 6
  255.    Bar 49,170 To 64,185
  256.    ' Clear zoom area
  257.    Ink 0
  258.    Bar 72,153 To 108,189
  259.    
  260.    ' 16 colors, get and set different components
  261.    ' Data block +$60 - $7f palette, 16 colors, 16 bits per color
  262.    '
  263.    '    bit  15  14  13  12  11  10   9   8   7   6   5   4   3   2   1   0 
  264.    '         ??  B4  B3  B2  B1  B0  G4  G3  G2  G1  G0  R4  R3  R2  R1  R0 
  265.    '             ------------------  ------------------  ------------------ 
  266.    '                  Blue data           Green data           Red data 
  267.    For CLR=0 To 15
  268.       ' ARS = Color address
  269.       ARS=Start(3)+IMAGE*$2000+$60+CLR*2
  270.       ' 16 bits, LSB to MSB
  271.       WORD=Peek(ARS)+Peek(ARS+1)*$100
  272.       ' 5 bits per component, drop LSB out 
  273.       RED=(WORD and $1F)/2
  274.       GREEN=(WORD and $3E0)/$40
  275.       BLUE=(WORD and $7C00)/$800
  276.       Colour 16+CLR,$100*RED+$10*GREEN+BLUE
  277.    Next CLR
  278.    
  279.    ' Get number of icon frames
  280.    ' Data block +2    bits 0-3 = icon count 
  281.    '                  bits 4-7 = icon display flag
  282.    FRAMES=Peek(Start(3)+IMAGE*$2000+2) and $F
  283.    ' Get blitter objects from buffer screen 
  284.    For FRAME=1 To FRAMES
  285.       Get Bob 1,FRAME,(FRAME-1)*16,(IMAGE-1)*16 To FRAME*16,IMAGE*16
  286.    Next FRAME
  287.    
  288.    ' Output save name to bottom of screen 
  289.    Ink 0,0
  290.    Bar 48,191 To 319,199
  291.    Ink 6,0
  292.    Text 48,198,Left$(NAMES$(IMAGE),32)
  293. Else 
  294.    ' v0.06 bug fixed, occured if 1st block wasn't in use    
  295.    FRAMES=0
  296. End If 
  297.  
  298. Return 
  299.  
  300.  
  301. '----------------------------------------------------------
  302. ' Get savenames and make icons to buffer 
  303. '
  304. MAKEICONS:
  305.  
  306. ' Clear text window area 
  307. Screen 0
  308. Ink 4,4
  309. Bar 121,31 To 269,179
  310.  
  311. ' 15 save blocks 
  312. For IM=1 To 15
  313.    ' Clear old name 
  314.    NAMES$(IM)=""
  315.    ' Check if block is in use 
  316.    If Peek(Start(3)+IM*$80)=$51
  317.       ' ARS = Current block address
  318.       ARS=Start(3)+IM*$2000
  319.       
  320.       ' Make filename
  321.       N=0
  322.       Repeat 
  323.          ' One character = 16 bits
  324.          WORD=Deek(ARS+4+2*N)
  325.          If WORD<>0
  326.             CLR=(WORD and $FF00)/$100
  327.             CHR=WORD and $FF
  328.             ' SPC = put space if char is not supported 
  329.             SPC=True
  330.             If CLR=$82
  331.                ' a..z 
  332.                If(CHR>$80 and CHR<$9B)
  333.                   SPC=0
  334.                   NAMES$(IM)=NAMES$(IM)+Chr$(CHR-$20)
  335.                End If 
  336.                ' A..Z 
  337.                If(CHR>$5F and CHR<$7A)
  338.                   SPC=0
  339.                   NAMES$(IM)=NAMES$(IM)+Chr$(CHR-$1F)
  340.                End If 
  341.                ' 0..9 
  342.                If(CHR>$4E and CHR<$59)
  343.                   SPC=0
  344.                   NAMES$(IM)=NAMES$(IM)+Chr$(CHR-$1F)
  345.                End If 
  346.             End If 
  347.             If CLR=$81
  348.                ' «
  349.                If CHR=$E1
  350.                   SPC=0
  351.                   NAMES$(IM)=NAMES$(IM)+Chr$($AB)
  352.                End If 
  353.                ' »
  354.                If CHR=$E2
  355.                   SPC=0
  356.                   NAMES$(IM)=NAMES$(IM)+Chr$($BB)
  357.                End If 
  358.                ' other character from table (bank 6)
  359.                If(CHR>$3F and CHR<$99)
  360.                   SPC=0
  361.                   NAMES$(IM)=NAMES$(IM)+Chr$(Peek(Start(6)+CHR-$40))
  362.                End If 
  363.             End If 
  364.             ' put space if char wasn't supported 
  365.             If SPC
  366.                NAMES$(IM)=NAMES$(IM)+" "
  367.             End If 
  368.             
  369.          End If 
  370.          Inc N
  371.          ' 0 = end of name, (N just if data is broken)  
  372.       Until N>31 or WORD=0
  373.       
  374.       ' Output 18 chars from name to text area 
  375.       Screen 0
  376.       Ink 6,4
  377.       Text 123,28+IM*10,Left$(NAMES$(IM),18)
  378.       
  379.       ' Make icon image
  380.       Screen 1
  381.       ' Data block +2    bits 0-3 = icon count 
  382.       FRAMES=Peek(ARS+2) and $F
  383.       For FRAME=1 To FRAMES
  384.          ' Data block + icon*$80 = start of icon pixel data 
  385.          ' 4 bits per pixel, one icon = $80 bytes 
  386.          ARS=ARS+$80
  387.          For YP=0 To 15
  388.             For XP=0 To 7
  389.                WORD=Peek(ARS+YP*8+XP)
  390.                CLR=WORD and $F
  391.                Plot(FRAME-1)*16+XP*2,(IM-1)*16+YP,CLR+16
  392.                CLR=(WORD and $F0)/$10
  393.                Plot(FRAME-1)*16+XP*2+1,(IM-1)*16+YP,CLR+16
  394.             Next XP
  395.          Next YP
  396.       Next FRAME
  397.       
  398.    End If 
  399. Next IM
  400. ' Set current image to 1 and draw icon 
  401. IMAGE=1
  402. Gosub ICON
  403. Return 
  404.  
  405.  
  406. '----------------------------------------------------------
  407. ' Load memcard file to memory bank 3 
  408. FILE_LOAD:
  409.  
  410. ' Requester
  411. FILE$=Fsel$("","","Load PSX-memcard file")
  412.  
  413. ' If filename was chosen 
  414. If FILE$<>""
  415.    ' Clear GOOD and BAD indicators  
  416.    Ink 6
  417.    Paint 121,24
  418.    Paint 184,24
  419.    
  420.    ' Reserve memory, loading a file bigger than 140000 bytes causes problems  
  421.    Erase 3
  422.    Reserve As Data 3,140000
  423.    ' Binary load  
  424.    Bload FILE$,Start(3)
  425.    
  426.    ' .gme format file 
  427.    ' Cut $F40 bytes from start
  428.    If Leek(Start(3))=$3132332D
  429.       Reserve As Work 2,132000
  430.       Copy Start(3)+$F40,Start(3)+$20F40 To Start(2)
  431.       Copy Start(2),Start(2)+$20000 To Start(3)
  432.       Erase 2
  433.    End If 
  434.    
  435.    ' .psx format file 
  436.    If(Instr(Lower$(FILE$),".psx")>0) and Not(Deek(Start(3))=$4D43)
  437.       Reserve As Work 2,132000
  438.       
  439.       ' Copy empty directory block in the start of work buffer 
  440.       Copy Start(7),Start(7)+$1E000 To Start(2)
  441.       
  442.       ' Modify directory block 
  443.       N=0
  444.       ' Put game id
  445.       Repeat 
  446.          BYTE=Peek(Start(3)+N)
  447.          Poke Start(2)+$8A+N,BYTE
  448.          Inc N
  449.       Until BYTE=0 or N>50
  450.       ' Calculate xor flag 
  451.       BYTE=0
  452.       For N=$80 To $FE
  453.          BYTE=BYTE xor Peek(Start(2)+N)
  454.       Next N
  455.       Poke Start(2)+$FF,BYTE
  456.       
  457.       Copy Start(3)+$36,Start(3)+$2036 To Start(2)+$2000
  458.       ' Check if .psx-file was a .psx file 
  459.       If Not(Deek(Start(3)+$36)=$5343)
  460.          Doke Start(2),0
  461.       End If 
  462.       Copy Start(2),Start(2)+$20000 To Start(3)
  463.       Erase 2
  464.    End If 
  465.    
  466.    ' If file was bad or good
  467.    If Not(Deek(Start(3))=$4D43)
  468.       Ink 15
  469.       Paint 184,24
  470.    Else 
  471.       Ink 8
  472.       Paint 121,24
  473.    End If 
  474.    
  475. End If 
  476. Return 
  477.  
  478.  
  479. '----------------------------------------------------------
  480. ' Save whole memorycard file 
  481. FILE_SAVE:
  482. ' Requester
  483. FILE$=Fsel$("","","Save raw PSX-memcard file")
  484. ' If name was chosen 
  485. If FILE$<>""
  486.    Bsave FILE$,Start(3) To Start(3)+$20000
  487. End If 
  488. Return 
  489.  
  490.  
  491. '----------------------------------------------------------
  492. ' Read memorycard via hardware and parallelport  
  493. CARD_READ:
  494. ' Clear position indicator, GOOD&BAD indicators  
  495. Ink 4,4,4
  496. Bar 32,13 To 287,15
  497. Ink 6
  498. Paint 121,24
  499. Paint 184,24
  500.  
  501. ' No errors  
  502. ERR=0
  503.  
  504. ' Reserve memory 
  505. Erase 3
  506. Reserve As Data 3,132000
  507. ' ADRS = byte position 
  508. ADRS=0
  509. ' SAV = save bits from hardware to memory  
  510. SAV=False
  511.  
  512. ' Parallel data bits 
  513. ' I designed hardware to be pc-parallel port combatible (except getting power),  
  514. ' standard pc-parallel port is very stupid, designed only for printing..   
  515.  
  516. ' D0   => command 0=0,1=1    
  517. ' D1   => clock, H\L edge action   
  518. ' D2   => select, 0=active 
  519. ' BUSY <= data in 0=0,1=1
  520. ' POUT <= acknowledge 0=active, not used yet, should be 0 after every 8 bit  
  521.  
  522. ' D0,D1,D2 output
  523. Poke $BFE301,7
  524. ' BUSY input 
  525. Bclr 0,$BFD200
  526. ' POUT input   
  527. Bclr 1,$BFD200
  528.  
  529. ' Whole memorycard = 1024 times 128 byte block 
  530. ' It's not hard to use only required blocks, I'm just lazy...  
  531. For N=0 To 1023
  532.    ' CHCK = check read end flag ('G'=good, 'N'=not good)
  533.    CHCK=False
  534.    ' Outputs to high
  535.    Poke $BFE101,$FF
  536.    ' Select memorycard
  537.    Bclr 1,$BFE101
  538.    
  539.    ' C=command
  540.    ' Command header 4 bytes 
  541.    C=$81 : Gosub SUB_READ
  542.    C=$52 : Gosub SUB_READ
  543.    C=0 : Gosub SUB_READ
  544.    C=0 : Gosub SUB_READ
  545.    ' Read address, $000..$3FF 
  546.    C=N/256 : Gosub SUB_READ
  547.    C=N and $FF : Gosub SUB_READ
  548.    ' Command acknowledge
  549.    C=0 : Gosub SUB_READ
  550.    ' Data header
  551.    C=0 : Gosub SUB_READ
  552.    ' Data address 
  553.    C=0 : Gosub SUB_READ
  554.    C=0 : Gosub SUB_READ
  555.    ' Data block, 128 bytes, save to memory
  556.    For B=0 To 127
  557.       C=0 : SAV=True : Gosub SUB_READ
  558.    Next B
  559.    ' xor code   
  560.    C=0 : Gosub SUB_READ
  561.    ' Read end flag    
  562.    C=0 : CHCK=True : Gosub SUB_READ
  563.    ' If not good
  564.    If RET<>$47 : Inc ERR : End If 
  565.    
  566.    ' Draw position indicator
  567.    Ink 15-(N/128)
  568.    Draw 32+N/4,13 To 32+N/4,15
  569. Next N
  570.  
  571. ' GOOD/BAD thing 
  572. If ERR>0
  573.    Ink 15
  574.    Paint 184,24
  575. Else 
  576.    Ink 8
  577.    Paint 121,24
  578. End If 
  579.  
  580. Return 
  581.  
  582. ' 8 bits per command 
  583. SUB_READ:
  584. For BIT=0 To 7
  585.    ' Output CMD bit 
  586.    If Btst(BIT,C)
  587.       Bset 0,$BFE101
  588.    Else 
  589.       Bclr 0,$BFE101
  590.    End If 
  591.    
  592.    ' CLK=0  
  593.    Bclr 2,$BFE101
  594.    ' Simple stupid delay  
  595.    For DELAY=0 To SPEED : Next DELAY
  596.    
  597.    ' Save DAT to memory 
  598.    If SAV
  599.       If Btst(0,$BFD000)
  600.          Bset BIT,Start(3)+ADRS
  601.       Else 
  602.          Bclr BIT,Start(3)+ADRS
  603.       End If 
  604.    End If 
  605.    
  606.    ' Read end flag check
  607.    If CHCK
  608.       If Btst(0,$BFD000)
  609.          Bset BIT,RET
  610.       Else 
  611.          Bclr BIT,RET
  612.       End If 
  613.    End If 
  614.    
  615.    ' CLK=1
  616.    Bset 2,$BFE101
  617.    ' Simple stupid delay  
  618.    For DELAY=0 To SPEED : Next DELAY
  619. Next BIT
  620. ' Increase current byte address
  621. If SAV
  622.    Inc ADRS
  623. End If 
  624. SAV=False
  625. Return 
  626.  
  627.  
  628.  
  629. '----------------------------------------------------------
  630. ' Write data to memorycard via hardware and parallelport 
  631. CARD_WRITE:
  632.  
  633. ' Clear position indicator, GOOD&BAD indicators  
  634. Ink 4,4,4
  635. Bar 32,13 To 287,15
  636. Ink 6
  637. Paint 121,24
  638. Paint 184,24
  639.  
  640. ERR=0
  641. DAT_OFFSET=0
  642. ' Enable output signals
  643. Poke $BFE301,7
  644. ' Enable input signals   
  645. ' Data in  
  646. Bclr $BFD200,0
  647. ' Acknowledge in 
  648. Bclr $BFD200,1
  649. ' 1024 128byte blocks
  650. For N=0 To 1023
  651.    ' Output high
  652.    Poke $BFE101,$FF
  653.    ' Select 
  654.    Bclr 1,$BFE101
  655.    
  656.    ' Command header 
  657.    C=$81 : Gosub WRITE_SUB
  658.    C=$57 : Gosub WRITE_SUB
  659.    C=0 : Gosub WRITE_SUB
  660.    C=0 : Gosub WRITE_SUB
  661.    
  662.    ' Write address
  663.    ' X = xor code 
  664.    C=N/256 : Gosub WRITE_SUB
  665.    X=C
  666.    C=N and $FF : Gosub WRITE_SUB
  667.    X=C xor X
  668.    
  669.    ' Data bytes 
  670.    For B=0 To 127
  671.       C=Peek(Start(3)+DAT_OFFSET) : Gosub WRITE_SUB
  672.       X=C xor X
  673.       Inc DAT_OFFSET
  674.    Next B
  675.    
  676.    ' Send xor code
  677.    C=X : Gosub WRITE_SUB
  678.    
  679.    ' Write end mark 
  680.    C=0 : Gosub WRITE_SUB
  681.    C=0 : Gosub WRITE_SUB
  682.    
  683.    ' Write end flag 
  684.    C=0 : Gosub WRITE_SUB
  685.    ' Good?
  686.    If RET<>$47 : Inc ERR : End If 
  687.    
  688.    ' Position indicator 
  689.    Ink 15-(N/128)
  690.    Draw 32+N/4,13 To 32+N/4,15
  691. Next N
  692. If ERR>0
  693.    Ink 15
  694.    Paint 184,24
  695. Else 
  696.    Ink 8
  697.    Paint 121,24
  698. End If 
  699. Return 
  700.  
  701. WRITE_SUB:
  702. ' 8 bits 
  703. For BIT=0 To 7
  704.    ' Send CMD bit 
  705.    If Btst(BIT,C)
  706.       Bset 0,$BFE101
  707.    Else 
  708.       Bclr 0,$BFE101
  709.    End If 
  710.    ' CLK = 0
  711.    Bclr 2,$BFE101
  712.    ' Simple stupid delay
  713.    For DELAY=0 To SPEED : Next DELAY
  714.    
  715.    ' Get DAT bit  
  716.    If Btst(0,$BFD000)
  717.       Bset BIT,RET
  718.    Else 
  719.       Bclr BIT,RET
  720.    End If 
  721.    ' CLK = 1
  722.    Bset 2,$BFE101
  723.    For DELAY=0 To SPEED : Next DELAY
  724. Next BIT
  725. Return 
  726.  
  727.  
  728. '----------------------------------------------------------
  729. UNDEL:
  730. ' Marks deleted files 'busy' 
  731. '     * directory frame
  732. '          +00     data flag 
  733. '                  bit 7-4         A  free(not use , delete) 
  734. '                                  5  busy 
  735. '                                  F  reserve
  736. '                  bit 3-0         0  not use
  737. '                                  1  top block
  738. '                                  2  link block 
  739. '                                  3  link end block 
  740. '                                  F  reserve
  741. For N=1 To 15
  742.    ADRS=N*$80+Start(3)
  743.    BYTE=Peek(ADRS)
  744.    If(BYTE and $F0)=$A0
  745.       Poke ADRS,BYTE xor $F0
  746.       BYTE=Peek(ADRS+$7F)
  747.       Poke ADRS,BYTE xor $F0
  748.    End If 
  749. Next N
  750. Gosub CARD_WRITE
  751. Return 
  752.  
  753. '----------------------------------------------------------
  754. ' Fill memory card with zeros
  755. ' Sometimes when you cannot use saveblocks in a PSX, 
  756. ' this will probably help..
  757. FOHMAT:
  758. Ink 4,4,4
  759. Bar 32,13 To 287,15
  760. Ink 6
  761. Paint 121,24
  762. Paint 184,24
  763. ERR=0
  764. ' Enable output signals
  765. Poke $BFE301,7
  766. ' Enable input signals   
  767. ' Data in  
  768. Bclr $BFD200,0
  769. ' Acknowledge in 
  770. Bclr $BFD200,1
  771. ' 1024 138byte transfers 
  772. For N=0 To 1023
  773.    Poke $BFE101,$FF
  774.    Bclr 1,$BFE101
  775.    C=$81 : Gosub WRITE_SUB
  776.    C=$57 : Gosub WRITE_SUB
  777.    C=0 : Gosub WRITE_SUB
  778.    C=0 : Gosub WRITE_SUB
  779.    C=N/256 : Gosub WRITE_SUB
  780.    X=C
  781.    C=N and $FF : Gosub WRITE_SUB
  782.    X=C xor X
  783.    For B=0 To 127
  784.       C=0 : Gosub WRITE_SUB
  785.       X=C xor X
  786.       Inc DAT_OFFSET
  787.    Next B
  788.    C=X : Gosub WRITE_SUB
  789.    C=0 : Gosub WRITE_SUB
  790.    C=0 : Gosub WRITE_SUB
  791.    C=0 : Gosub WRITE_SUB
  792.    If RET<>$47 : Inc ERR : End If 
  793.    Ink 15-(N/128)
  794.    Draw 32+N/4,13 To 32+N/4,15
  795. Next N
  796. If ERR>0
  797.    Ink 15
  798.    Paint 184,24
  799. Else 
  800.    Ink 8
  801.    Paint 121,24
  802. End If 
  803. Return 
  804.